﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;
using Bll;
namespace WebApiServer.Controllers
{
    public class OrderController : ApiController
    {
        OrderBll bll = new OrderBll();

        #region 显示订单
        [HttpGet]
        /// <summary>
        /// 显示订单
        /// </summary>
        /// <returns></returns>

        public List<Order> GetShowOrder(int id)
        {
            return bll.ShowOrder(id);

        }
        #endregion

        #region 添加订单
        /// <summary>
        /// 添加订单
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public int GetAddOrders(int carid,int UserId)
        {
            UsertBLL userbll = new UsertBLL();
            List<Usert> lis = userbll.showuser();
            Usert ls = lis.Where(p => (p.Userid == UserId)).FirstOrDefault();

            CarBLL carbll = new CarBLL();
            List<Car> list = carbll.SelCar(UserId);
            Car lst = list.Where(p => (p.CarId == carid)).FirstOrDefault();


            Order n=new Order();
            n.OrderName=lst.CarName;
            n.OrderPhone=ls.Utel;
            n.Orderprice=lst.CarPrice;
            n.OrderNum=lst.CarNum;
            n.OrderSum=lst.CarNum*lst.CarPrice;
            n.OrderAddr=ls.Uaddr;
            n.OrderDate=DateTime.Now;
            n.OrderPayStates="未支付";
            n.OrderStates="未配送";
            n.UserId=UserId;

            int i = bll.AddOrder(n,carid);
        
            return i;
        }
        #endregion

        #region  修改订单
        /// <summary>
        /// 修改订单
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public int PostuptOrder(Order n)
        {
            return bll.UptOrder(n);
        }
        #endregion

        #region 删除订单信息

        [HttpGet]
        /// <summary>
        /// 删除订单信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int GetDelOrder(string id)
        {
            return bll.DelOrder(id);
        }
        #endregion

        #region 清空订单
        /// <summary>
        /// 清空订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
  
           public int Getempty(int userid)
           {
               return bll.empty(userid);
           }
        #endregion

        #region 添加订单备注
           /// <summary>
      /// 添加订单备注
      /// </summary>
      /// <param name="advice"></param>
      /// <param name="email"></param>
      /// <param name="userid"></param>
      /// <returns></returns>

        public int GetAddOrder(string advice,string email,int userid)
        {
            int i = bll.AddAdvice(advice, email, userid);
            return i;
        }
           #endregion

    }
}
